'''
Created on Jan 17, 2010

@author: roman

$Id: cron.py 18 2010-01-20 11:14:09Z sigizmund $
'''


from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import users 
import logging

import feedreader

'''
class CronJobUrls(webapp.RequestHandler):
    def get(self):
        try:
            logging.info("CronJobUrls started")
            feedreader.reprocessUrls()
        except Exception, e:
            logging.error(e)


class CronJobAllUrls(webapp.RequestHandler):
    def get(self):
        logging.info("CronJobAllUrls started")
        try:
            feedreader.reprocessAllUrls()
        except Exception, e:
            logging.error(e)

class CronJobOldTweets(webapp.RequestHandler):
    def get(self):
#        try:
        logging.info("Trying to fetch oldtweets")
        feedreader.fetchOldUpdates(handler = self)
#        except Exception,e:
#            logging.error(e)
#            self.response.out.write("An exception's been caught, probably it was a time-out.")

'''

class CronJob(webapp.RequestHandler):
    def get(self):
        logging.info("Running routine cron job...")
        try:
            feedreader.readFeed()
        except Exception, e:
            logging.error(e)


def main():
    logging.getLogger().setLevel(logging.DEBUG)
    application = webapp.WSGIApplication([ 
                                          ('/cron', CronJob)
                                          ], debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
                                                          